/*
	Copyright (C) 2010- Peer internet solutions
	
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Modified by: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.mix;

import org.grupoavatar.guiaubicua.VDownloading;
import org.grupoavatar.guiaubicua.VInicial;
import org.grupoavatar.guiaubicua.entidades.ARMarker;
import org.grupoavatar.guiaubicua.mix.render.Matrix;
import org.grupoavatar.guiaubicua.mix.render.MixVector;
import org.grupoavatar.guiaubicua.punto.MasterActivity;

import android.content.Intent;


public class MixState {

	public static int NOT_STARTED = 0; 
	public static int PROCESSING = 1; 
	public static int READY = 2; 
	public static int DONE = 3; 

	int nextLStatus = MixState.NOT_STARTED;
	String downloadId;

	private float curBearing;
	private float curPitch;

	private boolean detailsView;

	public boolean handleEvent(MixContext ctx, Marker m) {
		try {
			
			if (DataView.viendoUnicoMarker)	{
				ctx.var.finish();
			}
			else	{
				Intent i = new Intent(VInicial.getContext(), VDownloading.class);
				i.putExtra("sigV", "poi");
				//VPOI.setPoi((ArpucpPOIMarker) m);
//				TabGeneral.setPoi((ArpucpPOIMarker) m);
//				TabUbicacion.setPoi((ArpucpPOIMarker) m);
//				TabServicios.setPoi((ArpucpPOIMarker) m);
				//MasterActivity.addPoi((ArpucpPOIMarker)m);
				MasterActivity._poi = (ARMarker)m;
//				MasterActivity._markerListTemporal = null;
				MasterActivity._bpoi = null;
				MasterActivity._poiHijoAnterior = null;
				i.putExtra("idPOI",  "setted");
				ctx.var.startActivity(i);
			}
		} catch (Exception ex) {
		}
		return true;
	}

	public float getCurBearing() {
		return curBearing;
	}

	public float getCurPitch() {
		return curPitch;
	}
	
	public boolean isDetailsView() {
		return detailsView;
	}
	
	public void setDetailsView(boolean detailsView) {
		this.detailsView = detailsView;
	}

	public void calcPitchBearing(Matrix rotationM) {
		MixVector looking = new MixVector();
		rotationM.transpose();
		looking.set(1, 0, 0);
		looking.prod(rotationM);
		this.curBearing = (int) (MixUtils.getAngle(0, 0, looking.x, looking.z)  + 360 ) % 360 ;

		rotationM.transpose();
		looking.set(0, 1, 0);
		looking.prod(rotationM);
		this.curPitch = -MixUtils.getAngle(0, 0, looking.y, looking.z);
	}
}
